#include <algorithm>
#include <cstdio>

const int N = 1e7 + 5;
int maxx;
int n, m;
bool vis[N];
int a[N], occ[N];
long long f[N];

int main() {
#ifndef ONLINE_JUDGE
#ifdef LOCAL
  freopen("testdata.in", "r", stdin);
  freopen("testdata.out", "w", stdout);
#else
  freopen("CF385C Bear and Prime Numbers.in", "r", stdin);
  freopen("CF385C Bear and Prime Numbers.out", "w", stdout);
#endif
#endif

  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) {
    scanf("%d", &a[i]);
    occ[a[i]]++;
    maxx = std::max(maxx, a[i]);
  }
  for (int i = 2; i <= maxx; ++i) {
    if (!vis[i]) {
      for (int j = 1; j * i <= maxx; ++j) {
        f[i] += occ[i * j];
        vis[i * j] = true;
      }
    }
  }
  for (int i = 1; i <= maxx; ++i) f[i] += f[i - 1];
  scanf("%d", &m);
  for (int i = 1, l, r; i <= m; ++i) {
    scanf("%d%d", &l, &r);
    if (l > maxx) {
      puts("0");
      continue;
    }
    r = std::min(r, maxx);
    printf("%lld\n", f[r] - f[l - 1]);
  }
  return 0;
}